package com.touringapp.android.utils.http;

import java.io.IOException;
import java.io.InputStream;

import org.apache.http.HttpResponse;
import org.json.JSONObject;

final class ApacheHttpResponseImpl implements com.touringapp.android.utils.http.HttpResponse {
    private HttpResponse httpResponse;
    private JSONObject json;
    private Integer httpStatusCode;
    private String requestUrl;
    
    public ApacheHttpResponseImpl(final String requestUrl, final JSONObject json, final int httpStatusCode) {
        this.json = json;
        this.httpStatusCode = httpStatusCode;
        this.requestUrl = requestUrl;
    }

    public ApacheHttpResponseImpl(final String requestUrl, final HttpResponse httpResponse) {
        this.httpResponse = httpResponse;
        this.requestUrl = requestUrl;
    }

    @Override
    public InputStream getResponseStream() throws IllegalStateException, IOException {
        return httpResponse.getEntity().getContent();
    }

    @Override
    public int getStatusCode() {
        return httpStatusCode == null ? httpResponse.getStatusLine().getStatusCode() : httpStatusCode;
    }


    @Override
    public JSONObject getJSONResult() {
        return json;
    }

    @Override
    public String getRequestUrl() {
        return requestUrl;
    }
    
    
}
